/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simframe.simulation;

/**
 *
 * @author Steve Noble
 */
public class Metric {

    public interface Compute  {
    public double exec();
}

    public enum Units {
        Dollars("$"),
        Num("#"),
        Percent("%") {
            @Override public String format() {
                return "#0 %";
            }
        };

        private final String symbol;

        Units(String symbol) {
            this.symbol = symbol;
        }

        @Override public String toString() {
            return symbol;
        }

        public String format() {
            return "#0E0";
        }
    }

    public interface Constrain<E extends SimObject> {
        public boolean allowed(E obj);
    }

		// immutable
		private final Compute compute;
		private final String name;
        private final Units units;
      

		// updates with metric
		double val;
		private Range range = new Range();

		public String getName() {

			return name;
		}

		public void setRange(double min, double max) {
			  range.setMinMax(min, max);
		}

		public Range getRange() {
			return range;
		}

        public Units getUnits() {
            return units;
        }

		public void update() {

			val = compute.exec();

			range.update(val);
		}

		public double val() {
			return val;
		}

		public Metric(String name, Units units, Compute computer)
		{
            this.compute = computer;
            this.units = units;
			this.name = name;
		}
}
